﻿#region Copyrights Notice
//©2009 Microsoft Corporation.  All rights reserved.
//This portal design is based on the design and some code from DropThings.com which is also licensed under an MS-PL license.
#endregion


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Caching;
using Microsoft.InformationSecurity.RiskManagement.ISRMWeb.RiskService;

namespace Microsoft.InformationSecurity.RiskManagement.ISRMWeb
{
    /// <summary>
    /// Summary description for PortalClientService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class PortalClientService : System.Web.Services.WebService
    {


        private string _UserName;

        public PortalClientService()
        {
            //Uncomment the following line if using designed components 
            //InitializeComponent();
            _UserName = Context.User.Identity.Name.Split('\\')[1].ToString();            
        }

        [WebMethod]
        public string GetSelectedMenuItemFromCache()
        {
            if (Context.Cache["SelectedMenuItem_" + _UserName] != null)
                return Context.Cache["SelectedMenuItem_" + _UserName].ToString();

            return "";
        }
        [WebMethod]
        public bool PutSelectedMenuItemInCache(string val)
        {
            if (Context.Cache["SelectedMenuItem_" + _UserName] != null)
                Context.Cache.Remove("SelectedMenuItem_" + _UserName);

            Context.Cache.Insert("SelectedMenuItem_" + _UserName, val, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));

            return true;
        }

        [WebMethod]
        public string[] GetCompletionList(string prefixText, int count)
        {
            string[] listAliases = null;
            RiskService.ManageRiskClient riskServiceClient = new RiskService.ManageRiskClient();
            listAliases = riskServiceClient.GetTOPNAliases(prefixText);
            riskServiceClient.Close();

            return listAliases;
        }

    }
}
